/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package com.jodinfo.outmirror.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

// Referenced classes of package com.hero.core.util:
//            StringUtils

public class DateUtils
{

    public DateUtils()
    {
    }

    public static String format(Date date, String pattern)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    public static int remainInToday()
    {
        long now = System.currentTimeMillis() + (long)TimeZone.getDefault().getOffset(System.currentTimeMillis());
        return Long.valueOf(86400L - (now / 1000L) % 86400L).intValue();
    }

    public static boolean inSameDay(Date date1, Date date2)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date1);
        int dayOfYear = calendar.get(6);
        int year = calendar.get(1);
        calendar.setTime(date2);
        return calendar.get(1) == year && calendar.get(6) == dayOfYear;
    }

    public static boolean inTime(Date date, Date startDate, int period, int periodUnit)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        calendar.add(periodUnit, period);
        return calendar.after(date);
    }

    public static boolean checkIsFirstWeek(Date date)
    {
        return System.currentTimeMillis() - date.getTime() < 604800000L;
    }

    public static boolean checkIsCurrentDay(Date date)
    {
        String pattern = "yyyy-MM-dd";
        return format(date, pattern).equals(format(new Date(), pattern));
    }

    public static final Date getDatePlusHour(Date date, int hour)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(11, hour);
            return cal.getTime();
        }
    }

    public static final Date getDatePlusDay(Date date, int day)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(5, day);
            return cal.getTime();
        }
    }

    public static final String DateToString(String aMask, Date date)
    {
        if(date == null)
        {
            return null;
        } else
        {
            SimpleDateFormat df = null;
            df = new SimpleDateFormat(aMask);
            return df.format(date);
        }
    }

    public static final Date getDatePlusMonth(Date date, int month)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(2, month);
            return cal.getTime();
        }
    }

    public static final Date getDatePlusDayHHMMSS(Date date, int day)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(5, day);
            cal.set(11, 0);
            cal.set(12, 0);
            cal.set(13, 0);
            return cal.getTime();
        }
    }

    public static final Date stringToDate(String aMask, String strDate)
    {
        if(strDate == null || strDate.isEmpty())
            return null;
        SimpleDateFormat df = null;
        Date date = null;
        df = new SimpleDateFormat(aMask);
        try
        {
            date = df.parse(strDate);
        }
        catch(ParseException pe)
        {
            pe.printStackTrace();
        }
        return date;
    }

    public static final String dbDateSubStr(String dateStr)
    {
        if(dateStr == null || dateStr.isEmpty())
            return dateStr;
        dateStr = dateStr.replace("T", " ");
        int index = dateStr.indexOf(".");
        if(index == -1)
            return dateStr;
        else
            return dateStr.substring(0, index);
    }

    public static final String dbDateSubStr2(String dateStr)
    {
        if(dateStr == null || dateStr.isEmpty())
            return dateStr;
        if(dateStr.length() < 10)
            return dateStr;
        else
            return dateStr.substring(0, 10);
    }

    public static final String dbDateToDisplay(String dateStr)
    {
        if(dateStr == null || dateStr.isEmpty())
            return dateStr;
        int index = dateStr.indexOf(".");
        if(index == -1)
            return dateStr;
        else
            return dateStr.substring(0, index - 3);
    }

    public static SimpleDateFormat dateFormat(Object value)
    {
        SimpleDateFormat sdf = null;
        if(value.toString().contains("00:00:00"))
            sdf = new SimpleDateFormat("yyyy-MM-dd");
        else
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf;
    }

    public static Date DateAddMonth(Date date, Integer n)
    {
        if(date == null || n == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(2, n.intValue());
            return cal.getTime();
        }
    }

    public static final String getCurrentTime()
    {
        SimpleDateFormat df = null;
        df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(new Date());
    }

    public static final String getCurrentTimeNum()
    {
        SimpleDateFormat df = null;
        df = new SimpleDateFormat("yyyyMMddHHmmss");
        return df.format(new Date());
    }

    public static Date parse(String strDate)
        throws ParseException
    {
        return StringUtils.isBlank(strDate) ? null : parse(strDate, "yyyy-MM-dd");
    }

    public static Date parse(String strDate, String pattern)
        throws ParseException
    {
        return StringUtils.isBlank(strDate) ? null : (new SimpleDateFormat(pattern)).parse(strDate);
    }

    public static Date getFirstDateOfLastMonth(Date date)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(2, -1);
            cal.set(5, 1);
            cal.set(11, 0);
            cal.set(12, 0);
            cal.set(13, 0);
            return cal.getTime();
        }
    }

    public static Date getEndDateOfLastMonth(Date date)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(2, -1);
            cal.set(5, cal.getActualMaximum(5));
            cal.set(11, 23);
            cal.set(12, 59);
            cal.set(13, 59);
            return cal.getTime();
        }
    }

    public static Date getFirstDateOfMonth(Date date)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar dateCalendar = Calendar.getInstance();
            dateCalendar.setTime(date);
            dateCalendar.set(5, 1);
            dateCalendar.set(11, 0);
            dateCalendar.set(12, 0);
            dateCalendar.set(13, 0);
            return dateCalendar.getTime();
        }
    }

    public static Date getEndDateOfMonth(Date date)
    {
        if(date == null)
        {
            return null;
        } else
        {
            Calendar dateCalendar = Calendar.getInstance();
            dateCalendar.setTime(date);
            int maxDay = dateCalendar.getActualMaximum(5);
            dateCalendar.set(5, maxDay);
            dateCalendar.set(11, 23);
            dateCalendar.set(12, 59);
            dateCalendar.set(13, 59);
            return dateCalendar.getTime();
        }
    }

    public static int getDayOfMonth(String strDate)
    {
        Date date = stringToDate("yyyy-MM-dd HH:mm:ss", strDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(5);
    }

    public static String getNextYyyyMM(String strDate)
    {
        Date date = stringToDate("yyyy-MM-dd HH:mm:ss", strDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(2, 1);
        Date date2 = cal.getTime();
        String rsStr = DateToString("yyyy-MM-dd HH:mm:ss", date2);
        return rsStr.substring(0, 7);
    }

    public static int DateCompare(String strDate1, String strDate2)
    {
        Date date1 = stringToDate("yyyy-MM-dd HH:mm:ss", strDate1);
        Date date2 = stringToDate("yyyy-MM-dd HH:mm:ss", strDate2);
        return date1.compareTo(date2);
    }

    public static List getAllDateBetween2Date(String startTime, String endTime)
    {
        List dateList = new ArrayList();
        try
        {
            Calendar startCalendar = Calendar.getInstance();
            Calendar endCalendar = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date startDate = df.parse(startTime);
            startCalendar.setTime(startDate);
            Date endDate = df.parse(endTime);
            endCalendar.setTime(endDate);
            dateList.add(startTime);
            do
            {
                startCalendar.add(5, 1);
                if(startCalendar.getTimeInMillis() >= endCalendar.getTimeInMillis())
                    break;
                dateList.add(df.format(startCalendar.getTime()));
            } while(true);
            dateList.add(endTime);
        }
        catch(ParseException e)
        {
            e.getLocalizedMessage();
        }
        return dateList;
    }

    public static void main(String args[])
    {
        String strDateCom = "2016-01-21 10:11:13";
        String strDateCom2 = "2016-01-21 10:11:12";
        System.out.println(getNextYyyyMM(strDateCom));
    }

    public static String format(Timestamp date, String pattern)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    public static final String TIMEPATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String TIMEPATTERN_HHMM = "yyyy-MM-dd HH:mm";
    public static final String TIMEPATTERN_HHMM_CN = "yyyy\u5E74MM\u6708dd\u65E5 HH:mm";
    public static final String TIMEPATTERN_YYYYMMDD = "yyyy-MM-dd";
    public static final String MY_DATE_FORMAT_YMD = "yyyyMMdd";
    public static final String TIMEPATTERN_YYYYMM = "yyyy-MM";
    public static final String TIMEPATTERN_yyyyMMddHHmmss = "yyyyMMddHHmmss";
    private static final long oneWeekSecond = 604800000L;
}


/*
	DECOMPILATION REPORT

	Decompiled from: E:\meaven-localRepository1\com\hero\common_core_api\0.0.1-ASSET-SNAPSHOT\common_core_api-0.0.1-ASSET-SNAPSHOT.jar
	Total time: 511 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/